/**
 * Copyright (c) 2018-2022, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 * 
 * Contains: vbe header
 * 
 * Change Logs:
 * Date           Author            Notes
 * 2022-06-03     JasonHu           Init
 */

#ifndef __DRIVER_VBE_H__
#define __DRIVER_VBE_H__

#include <nxos_mini.h>

#define VBE_BASE_INFO_ADDR 0x00001100
#define VBE_BASE_MODE_ADDR 0x00001300

struct VbeInfoBlock {
    NX_U8 vbeSignature[4];        /* VEB Signature: 'VESA' */
    NX_U16 vbeVeision;            /* VEB Version:0300h */
    NX_U32 oemStringPtr;          /* VbeFarPtr to OEM string */
    NX_U8 capabilities[4];        /* Capabilities of graphics controller */
    NX_U32 videoModePtr;          /* VbeFarPtr to VideoModeList */
    NX_U16 totalMemory;           /* Number of 64kb memory blocks added for VEB2.0+ */
    NX_U16 oemSoftwareRev;        /* VEB implementation Software revision */
    NX_U32 oemVendorNamePtr;      /* VbeFarPtr to Vendor Name String */
    NX_U32 oemProductNamePtr;     /* VbeFarPtr to Product Name String */
    NX_U32 oemProductRevPtr;      /* VbeFarPtr to Product Revision String */
    NX_U8 reserved[222];          /* Reserved for VBE implementation scratch area */
    NX_U8 oemData[256];           /* Data Area for OEM String */
} __attribute__ ((packed));

struct VbeModeInfoBlock {
    /* Mandatory information for all VBE revisions */
    NX_U16 modeAttributes;        /* mode attributes */
    NX_U8 winAAttributes;         /* window A attributes */
    NX_U8 winBAttributes;         /* window B attributes */
    NX_U16 winGranulaity;         /* window granulaity */
    NX_U16 winSize;               /* window size */
    NX_U16 winASegment;           /* window A start segment */
    NX_U16 winBSegment;           /* window B start segment */
    NX_U32 winFuncPtr;            /* real mode pointer to window function */
    NX_U16 bytesPerScanLine;      /* bytes per scan line */
    /* Mandatory information for VBE1.2 and above */
    NX_U16 xResolution;           /* horizontal resolution in pixels or characters */
    NX_U16 yResolution;           /* vertical resolution in pixels or characters */
    NX_U8 xCharSize;              /* character cell width in pixels */
    NX_U8 yCharSize;              /* character cell height in pixels */
    NX_U8 numberOfPlanes;         /* number of banks */
    NX_U8 bitsPerPixel;           /* bits per pixel */
    NX_U8 numberOfBanks;          /* number of banks */
    NX_U8 memoryModel;            /* memory model type */
    NX_U8 bankSize;               /* bank size in KB */
    NX_U8 numberOfImagePages;     /* number of images */
    NX_U8 reserved0;              /* reserved for page function: 1 */
    NX_U8 redMaskSize;            /* size of direct color red mask in bits */
    NX_U8 redFieldPosition;       /* bit position of lsb of red mask */
    NX_U8 greenMaskSize;          /* size of direct color green mask in bits */
    NX_U8 greenFieldPosition;     /* bit position of lsb of green mask */
    NX_U8 blueMaskSize;           /* size of direct color blue mask in bits */
    NX_U8 blueFieldPosition;      /* bit position of lsb of blue mask */
    NX_U8 rsvdMaskSize;           /* size of direct color reserved mask in bits */
    NX_U8 rsvdFieldPosition;      /* bit position of lsb of reserved mask */
    NX_U8 directColorModeInfo;    /* direct color mode attributes */

    /* Mandatory information for VBE2.0 and above */
    NX_U32 phyBasePtr;            /* physical address for flat memory frame buffer */
    NX_U32 reserved1;             /* reserved-always set to 0 */
    NX_U16 reserved2;             /* reserved-always set to 0 */
    /* Mandatory information for VBE3.0 and above */
    NX_U16 linebytesPerScanLine;  /* bytes per scan line for linear modes */
    NX_U8 bnkNumberOfImagePages;  /* number of images for banked modes */
    NX_U8 linNumberOfImagePages;  /* number of images for linear modes */
    NX_U8 linRedMaskSize;         /* size of direct color red mask(linear modes) */
    NX_U8 linRedFieldPosition;    /* bit position of lsb of red mask(linear modes) */
    NX_U8 linGreenMaskSize;       /* size of direct color green mask(linear modes) */
    NX_U8 linGreenFieldPosition;  /* bit position of lsb of green mask(linear modes) */
    NX_U8 linBlueMaskSize;        /* size of direct color blue mask(linear modes) */
    NX_U8 linBlueFieldPosition;   /* bit position of lsb of blue mask(linear modes) */
    NX_U8 linRsvdMaskSize;        /* size of direct color reserved mask(linear modes) */
    NX_U8 linRsvdFieldPosition;   /* bit position of lsb of reserved mask(linear modes) */
    NX_U32 maxPixelClock;         /* maximum pixel clock (in HZ) for graphics mode */
    NX_U8 reserved3[189];         /* remainder of ModeInfoBlock */
}  __attribute__ ((packed));

#endif /* __DRIVER_VBE_H__ */
